package creditnum;

import java.util.Scanner;

public class ConsoleInterface {
	private static final int MAX_NUMBER_LENGTH = 6;
	Scanner input = new Scanner(System.in);
	private UnderDHood program;

	public ConsoleInterface() {
		program = new UnderDHood();
	}

	void enterNumber() {
		System.out.println("Enter cardNumber");
		String cardNumber = input.nextLine();
		// trqbva da napravq proverka za max 50
		if (cardNumber != null && cardNumber != "") {
			if (!cardNumber.matches(".*[~!.......].*")
					&& cardNumber.length() >= MAX_NUMBER_LENGTH) {
				setCardNumber(cardNumber);
			} else {
				System.out
						.println("The card number you tried to enter has invalid symbols or is too short. Try again.");
				enterNumber();
			}
		}
	}
	void printMostCommon(){
		System.out.println(program.mostCommonNumber());
	}

	// setters and getters
	void setCardNumber(String cardNumber) {
		program.setCardNumber(cardNumber);
	}

	String getCardNumber(int cardPosition) {
		return program.getCardNumber(cardPosition);
	}

	public int getLength() {
		return program.getLength();
	}
}
